package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.BannerMapper;
import com.ruoyi.system.domain.Banner;
import com.ruoyi.system.service.IBannerService;

/**
 * 新品轮播图Service业务层处理
 * 
 * @author Wxl
 * @date 2022-03-28
 */
@Service
public class BannerServiceImpl implements IBannerService 
{
    @Autowired
    private BannerMapper bannerMapper;

    /**
     * 查询新品轮播图
     * 
     * @param bannerId 新品轮播图主键
     * @return 新品轮播图
     */
    @Override
    public Banner selectBannerByBannerId(Long bannerId)
    {
        return bannerMapper.selectBannerByBannerId(bannerId);
    }

    /**
     * 查询新品轮播图列表
     * 
     * @param banner 新品轮播图
     * @return 新品轮播图
     */
    @Override
    public List<Banner> selectBannerList(Banner banner)
    {
        return bannerMapper.selectBannerList(banner);
    }

    /**
     * 新增新品轮播图
     * 
     * @param banner 新品轮播图
     * @return 结果
     */
    @Override
    public int insertBanner(Banner banner)
    {
        banner.setCreateTime(DateUtils.getNowDate());
        return bannerMapper.insertBanner(banner);
    }

    /**
     * 修改新品轮播图
     * 
     * @param banner 新品轮播图
     * @return 结果
     */
    @Override
    public int updateBanner(Banner banner)
    {
        banner.setUpdateTime(DateUtils.getNowDate());
        return bannerMapper.updateBanner(banner);
    }

    /**
     * 批量删除新品轮播图
     * 
     * @param bannerIds 需要删除的新品轮播图主键
     * @return 结果
     */
    @Override
    public int deleteBannerByBannerIds(Long[] bannerIds)
    {
        return bannerMapper.deleteBannerByBannerIds(bannerIds);
    }

    /**
     * 删除新品轮播图信息
     * 
     * @param bannerId 新品轮播图主键
     * @return 结果
     */
    @Override
    public int deleteBannerByBannerId(Long bannerId)
    {
        return bannerMapper.deleteBannerByBannerId(bannerId);
    }

    @Override
    public List<String> getBycanteenId(Long canteenId) {
        List<Banner> bannerList = bannerMapper.selectList(new QueryWrapper<Banner>().eq("canteen_id", canteenId));
        List<String> list = new ArrayList();
        for (Banner banner : bannerList) {
            list.add("http://localhost:8000/dev-api"+banner.getBannerUrl());
        }
        return list;
    }
}
